
<template>
  <div class="app-container">
    <div class="search-container">
      <el-form ref="queryFormRef" :model="queryParams" label-width="auto" :inline="true">
        <el-form-item label="供应商" prop="supplierId">
          <el-select filterable clearable @keyup.enter="handleQuery" v-model="queryParams.supplierId" placeholder="请选择" style="width: 256px">
            <el-option v-for="item in supplierOptions" :key="item.id" :label="item.companyName" :value="item.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="提现账号" prop="withdrawAccount">
          <el-input @keyup.enter="handleQuery" v-model="queryParams.withdrawAccount" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="提现户名" prop="withdrawName">
          <el-input @keyup.enter="handleQuery" v-model="queryParams.withdrawName" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="status">
          <el-select clearable @keyup.enter="handleQuery" v-model="queryParams.status" placeholder="请选择" style="width: 256px">
            <el-option :value="0" label="待审核" />
            <el-option :value="1" label="通过" />
            <el-option :value="2" label="驳回" />
          </el-select>
        </el-form-item>
        <!-- <el-form-item label="账单时间" prop="billingTime">
          <el-date-picker style="width: 256px" v-model="queryParams.billingTime" type="month" format="YYYYMM" valueFormat="YYYYMM" clearable @keyup.enter="handleQuery" />
        </el-form-item> -->
        <el-form-item>
          <el-button type="primary" @click="handleQuery">
            <template #icon><Search /></template>
            搜索
          </el-button>
          <el-button @click="handleResetQuery">
            <template #icon><Refresh /></template>
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <template #header>
        <div class="upload_box">
          <el-button type="warning" preIcon="ant-design:export-outlined" @click="handleExports">导出</el-button>
        </div>
      </template>
      <el-table v-loading="loading" :data="TableData" highlight-current-row row-key="id" @row-click="handleRowClick">
        <el-table-column label="供应商" min-width="300" align="center" prop="supplierName">
          <template #default="scope">
            <div>{{ scope.row.supplierNo }}-{{ scope.row.supplierName }}</div>
          </template>
        </el-table-column>
        <el-table-column label="状态" min-width="120" align="center" prop="status">
          <template #default="scope">
            <div style="color: orange" v-if="scope.row.status == 0">待处理</div>
            <div style="color: #55d187" v-else-if="scope.row.status == 1">成功</div>
            <div style="color: red" v-else>失败</div>
          </template>
        </el-table-column>
        <el-table-column label="提现账号" min-width="120" align="center" prop="withdrawAccount"></el-table-column>
        <el-table-column label="提现户名" min-width="120" align="center" prop="withdrawName"></el-table-column>
        <el-table-column label="创建时间" min-width="140" align="center" prop="createTime"></el-table-column>
        <el-table-column label="原因" min-width="120" align="center" prop="reason"></el-table-column>
        <el-table-column label="审核人" min-width="120" align="center" prop="adminName"></el-table-column>
        <el-table-column label="审核时间" min-width="140" align="center" prop="updateTime"></el-table-column>
        <el-table-column fixed="right" align="center" label="操作" width="220">
          <template #default="scope">
            <div>
              <el-button v-hasPerm="['supplier/audit']" type="primary" link size="small" @click.stop="handleMoney(scope.row)">
                <template #icon><Pointer /></template>
                审核
              </el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-if="total > 0" v-model:total="total" v-model:page="queryParams.pageNo" v-model:limit="queryParams.pageSize" @pagination="handleQuery" />
    </el-card>
    <!-- 改派 -->
    <MoneyModal ref="modalRef" @success="handleQuery" />
  </div>
</template>

<script setup lang="ts">
import CommonApi from "@/api/common";
import { ref, onMounted, reactive } from "vue";
import { platFormEnum, channelEnum, platFormArr, channelArr } from "@/enums/common";
import { MenuTypeEnum } from "@/enums/MenuTypeEnum";
import ExportApi from "@/api/exports";
import MoneyApi from "@/api/money";
import Supplier from "@/api/supplier";
import MoneyModal from "./components/moneyModal.vue";

const queryFormRef = ref(ElForm);
const total = ref(0);
const supplierOptions = ref();
const modalRef = ref(null);
const cityOptions = ref();

const loading = ref(false);
// 点击供应商提现触
function handleMoney(row: any) {
  modalRef.value.edit(row);
}
function handleExports() {
  if (!queryParams.time) {
    ElMessage.error("请选择时间");
    return;
  }
  ExportApi.billExport(queryParams).then((res) => {
    let data = res.data;
    ElMessage.success("导出完毕");
    if (!data) {
      return;
    }
    if (typeof window.navigator.msSaveBlob !== "undefined") {
      window.navigator.msSaveBlob(new Blob([data], { type: "application/vnd.ms-excel" }), fileName + ".xls");
    } else {
      let url = window.URL.createObjectURL(new Blob([data], { type: "application/vnd.ms-excel" }));
      let link = document.createElement("a");
      link.style.display = "none";
      link.href = url;
      link.setAttribute("download", "账单" + ".xlsx");
      document.body.appendChild(link);
      link.click();
      document.body.removeChild(link); //下载完成移除元素
      window.URL.revokeObjectURL(url); //释放掉blob对象
    }
  });
}

// 查询参数
const queryParams = reactive<MenuQuery>({
  pageNo: 1,
  pageSize: 10,
});
// 菜单表格数据
const TableData = ref([]);

// 选择表格的行菜单ID
const selectedMenuId = ref<number | undefined>();

// 查询菜单
function handleQuery() {
  loading.value = true;
  Supplier.supplierAuditList(queryParams)
    .then((data) => {
      TableData.value = data.result;
      total.value = data.total * 1;
    })
    .finally(() => {
      loading.value = false;
    });
}
import router from "@/router";

// 重置查询
function handleResetQuery() {
  queryFormRef.value.resetFields();
  queryParams.pageNo = 1;
  handleQuery();
}

// 行点击事件
function handleRowClick(row: MenuVO) {
  // 记录表格选择的菜单ID，新增子菜单作为父菜单ID
  selectedMenuId.value = row.id;
}

onMounted(() => {
  handleQuery();
  CommonApi.getSupplier({ pageNo: 1, pageSize: 9999, status: 1 }).then((data) => {
    if (data.code == 0) {
      supplierOptions.value = data.result;
    }
  });
  CommonApi.getCity({ pageNo: 1, pageSize: 9999 }).then((data) => {
    if (data.code == 0) {
      cityOptions.value = data.result;
    }
  });
});
</script>
<style lang="scss" scoped>
.upload_box {
  display: flex;
  align-items: center;
  .upload-demo {
    margin: 0 4px;
  }
}
.red_rate {
  color: red;
}
.address_box {
  display: flex;
  flex-direction: column;
  align-items: left;
  justify-content: left;
  .item {
    display: flex;
    align-items: center;
    margin: 4px 0;
    .tag {
      width: 50px;
      height: 23px;
      text-align: center;
      color: orange;
      background: #fff8e6;
    }
    .tag2 {
      color: #3fd175;
      background: #e7faf0;
    }
  }
}
</style>
